<include file="Public/min-header"/>

<div class="wrapper">
    <include file="Public/breadcrumb"/>
	<section class="content">
       <div class="row">
       		<div class="col-xs-12">
	       		<div class="box">
	           	<div class="box-header">
	               <nav class="navbar navbar-default">	     
				        <div class="collapse navbar-collapse">
				          <form class="navbar-form form-inline" action="{:U('Promotion/group_buy_list')}" method="post">
				            <div class="form-group">
				              	<input type="text" name="keywords" class="form-control" placeholder="活动名称">
				            </div>
				            <div class="form-group">
				            	状态<select class="form-control" name="status">
				            		<option value="0">待审核</option>
				            		<option value="0">正常</option>
				            		<option value="0">结束</option>
				            		<option value="0">关闭</option>
				              	</select>
				            </div>
				            <button type="submit" class="btn btn-default">提交</button>          
				          </form>		
				      	</div>
	    			</nav>                
	             </div>	    
	             <!-- /.box-header -->
	             <div class="box-body">	             
	           		<div class="row">
	            	<div class="col-sm-12">
		              <table id="list-table" class="table table-bordered table-striped dataTable">
		                 <thead>
		                   <tr role="row" align="center">
			                   <th align="center">团购标题</th>
			                   <th class="sorting" tabindex="0">团购价</th>
			                   <th class="sorting" tabindex="0">开始时间</th>
			                   <th class="sorting" tabindex="0">结束时间</th>
			                   <th class="sorting" tabindex="0">已参团</th>
			                   <th class="sorting" tabindex="0">参团库存</th>
			                   <th class="sorting" tabindex="0">折扣</th>
			                   <th class="sorting" tabindex="0">状态</th>
			                   <th>推荐</th>
			                   <th class="sorting" tabindex="0">操作</th>
		                   </tr>
		                 </thead>
						<tbody>
						  <foreach name="list" item="vo" key="k" >
						  	<tr role="row" align="center">
		                     <td align="center">{$vo.title|getSubstr=0,30}</td>
		                     <td>{$vo.price}</td>
		                     <td>{$vo.start_time}</td>
		                     <td>{$vo.end_time}</td>
		                     <td>{$vo.buy_num}</td>
							 <td>{$vo.goods_num}</td>
							 <td>{$vo.rebate}</td>
							 <td>{$state[$vo[status]]}</td>
							 <th><img width="20" height="20" src="__PUBLIC__/images/<if condition='$vo[recommend] eq 1'>yes.png<else />cancel.png</if>" onclick="changeTableVal('group_buy','id','{$vo.id}','recommend',this)"/></th>
							 <td>
							 	<if condition="$vo['status'] eq 0">
		                      		<a href="javascript:;" class="btn btn-success" onclick="changeStatus(1,'{$vo.id}','group_buy')">通过</a>
		                      		<a href="javascript:;" class="btn btn-warning" onclick="changeStatus(2,'{$vo.id}','group_buy')">拒绝</a>
		                      	</if>
		                      	<if condition="$vo['status'] eq 1">
		                      		<a class="btn btn-warning" href="javascript:;" onclick="changeStatus(3,'{$vo.id}','group_buy')">取消</a>
		                      	</if>
		                        <a class="btn btn-danger" href="javascript:void(0)" data-url="{:U('Promotion/groupbuyHandle')}" data-id="{$vo.id}" onclick="delfunc(this)"><i class="fa fa-trash-o"></i></a>
							</td>
		                   </tr>
		                  </foreach>
		                   </tbody>
		                 <tfoot>
		                 
		                 </tfoot>
		               </table>
	               </div>
	          </div>
              <div class="row">
              	    <div class="col-sm-6 text-left"></div>
                    <div class="col-sm-6 text-right">{$page}</div>		
              </div>
	          </div><!-- /.box-body -->
	        </div><!-- /.box -->
       	</div>
       </div>
   </section>
</div>
<script>
function changeStatus(status,id,tab){
	if(status>1){
    	layer.confirm('确认删除？', {btn: ['确定','取消']}, function(){
	  			$.ajax({
	  				type : 'GET',
	  				url : "{:U('Promotion/activity_handle')}",
	  				data : {'id':id,'tab':tab,'status':status},
	  				dataType :'JSON',
	  				success : function(res){
	  					if(res == 1){
	  						layer.msg('操作成功', {icon: 1});
	  						window.location.reload();
	  					}else{
	  						layer.msg('操作失败', {icon: 2,time: 2000});
	  					}
	  					layer.closeAll();
	  				}
	  			});
  			}, function(index){
  				layer.close(index);
  				return false;// 取消
  			});
	}else{
		$.ajax({
			type : 'GET',
			url : "{:U('Promotion/activity_handle')}",
			data : {'id':id,'tab':tab,'status':status},
			dataType :'JSON',
			success : function(res){
				if(res == 1){
					layer.msg('操作成功', {icon: 1});
					window.location.reload();
				}else{
					layer.msg('操作失败', {icon: 2,time: 2000});
				}
				layer.closeAll();
			}
		});
	}
}
</script>  
</body>
</html>